package longestchar

import (
	"math"
	"strings"
)

func LengthOfLongestSubstring(s string) int {
	record := map[string]int{}
	chars := strings.Split(s, "")
	var max, min int
	for k, v := range chars {
		if _, ok := record[v]; ok {
			min = int(math.Max(float64(min), float64(record[v]+1)))
		}
		record[v] = k
		max = int(math.Max(float64(max), float64(k+1-min)))
	}
	return max
}
